/*
 * @Author: wjc
 * @Date: 2025-02-13 14:52:31
 * @LastEditors: wjc
 * @LastEditTime: 2025-10-28 11:38:24
 * @Description:
 */
import type { App, Directive } from 'vue'

import checkAction from '#/utils/check-action'

function checkActionEl(el: HTMLElement, binding: DirectiveBinding) {
  const { value } = binding

  if (!checkAction(value)) {
    el.remove()
  }
}

const vAction: Directive = {
  mounted: (el, binding) => {
    checkActionEl(el, binding)
  },
  updated(el, binding) {
    checkActionEl(el, binding)
  },
}

export function setupActionDirective(app: App) {
  app.directive('action', vAction)
}

export default vAction
